//
//  DirectCodecCopy.cpp
//  sad
//
//  Created by Christopher Kemsley on 2/4/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//

#include <iostream>
#include "Codec.hpp"
#include "URL.hpp"
#include "SystemCDefinitions.hpp"
#include "Model.hpp"


template <typename Type>
struct	DirectCopyCodec : public aCodec<Type*,Type>
{
	DirectCopyCodec ()
	:	aCodec<Type*,Type> ()
	{ }
	
	virtual bool	runDecode		( Any const & anyView , Any const & anyModel )
		{
		Type*			output	=	anyModel.as<Type*>() ;
		Type const&		input	=	anyView.as<Type>() ;
		
		*output = input ;
		
		return true ;
		}
} ;


DirectCopyCodec<std::string>	DirectCopyCodec_string ;
DirectCopyCodec<double>			DirectCopyCodec_double ;
DirectCopyCodec<int>			DirectCopyCodec_int ;
DirectCopyCodec<bool>			DirectCopyCodec_bool ;
DirectCopyCodec<URL>			DirectCopyCodec_path ;
DirectCopyCodec<SCInterval>		DirectCopyCodec_interval ;
DirectCopyCodec<ModelVariant>	DirectCopyCodec_ModelVariant ;






template <typename ViewType,typename ModelType>
struct	ConvertingCopyCodec : public aCodec<ModelType*,ViewType>
{
	ConvertingCopyCodec ()
	:	aCodec<ModelType*,ViewType> ()
	{ }
	
	virtual bool	runDecode		( Any const & anyView , Any const & anyModel )
		{
		ModelType*			output	=	anyModel.as<ModelType*>() ;
		ViewType const&		input	=	anyView.as<ViewType>() ;
		
		*output = input ;
		
		return true ;
		}
} ;


#define	ConvertingCopyCodecDef(letter,vType,mType)	ConvertingCopyCodec<vType,mType> ConvertingCopyCodec##letter ;


ConvertingCopyCodecDef ( a1 , double , unsigned ) ;
ConvertingCopyCodecDef ( b1 , double , unsigned long ) ;
ConvertingCopyCodecDef ( c1 , double , int ) ;
ConvertingCopyCodecDef ( d1 , double , long ) ;
ConvertingCopyCodecDef ( e1 , double , float ) ;
ConvertingCopyCodecDef ( f1 , double , char ) ;

ConvertingCopyCodecDef ( a2 , int , unsigned ) ;
ConvertingCopyCodecDef ( b2 , int , unsigned long ) ;
ConvertingCopyCodecDef ( c2 , int , double ) ;
ConvertingCopyCodecDef ( d2 , int , long ) ;
ConvertingCopyCodecDef ( e2 , int , float ) ;
ConvertingCopyCodecDef ( f2 , int , char ) ;

